<template>
  <section class="xm-content xm-role">
    <el-form ref="form"
      v-loading="box_loading"
      :model="form" :rules="rules"
      size="mini"
      label-width="100px" inline-message>

      <el-form-item label="重要级别" prop="importanceRank">
        <el-select v-model="form.cpkLevel" placeholder="请选择重要级别">
          <el-option value="0" label="次重要的" />
          <el-option value="1" label="略重要的" />
          <el-option value="2" label="重要的" />
          <el-option value="3" label="很重要的" />
          <el-option value="4" label="关键的" />
        </el-select>
      </el-form-item>

      <el-form-item label="code" prop="code">
        <el-input v-model="form.code" clearable placeholder="请输入code值" />
      </el-form-item>
      <el-form-item label="测量值" prop="testItem">
        <el-input v-model="form.testItem" clearable placeholder="请输入测量值" />
      </el-form-item>
      <el-form-item label="名称值" prop="nameValueK2101">
        <el-input v-model="form.nameValueK2101" clearable placeholder="请输入名称值" />
      </el-form-item>
      <el-form-item label="下限值" prop="lowValueK2110">
        <el-input v-model="form.lowValueK2110" clearable placeholder="请输入下限值" />
      </el-form-item>
      <el-form-item label="上限值" prop="highValueK2111">
        <el-input v-model="form.highValueK2111" clearable placeholder="请输入上限值" />
      </el-form-item>
      <el-form-item label="产品名" prop="consoleType">
        <el-input v-model="form.consoleType" clearable placeholder="请输入产品名" />
      </el-form-item>
      <el-form-item label="工位类型" prop="toolType">
        <el-select v-model="form.toolType" placeholder="请选择工位类型">
          <el-option value="1" label="atlas" />
          <el-option value="2" label="马头" />
          <el-option value="3" label="CTL" />
          <el-option value="4" label="蒂森NVH" />
          <el-option value="5" label="蒂森终检台" />
          <el-option value="6" label="霍塔NVH" />
          <el-option value="7" label="霍塔终检台" />
          <el-option value="8" label="kistler" />
          <el-option value="9" label="巨一" />
          <el-option value="10" label="sph" />
        </el-select>
      </el-form-item>
      <el-form-item label="工位" prop="importanceRank">
        <el-select v-model="form.station" filterable clearable placeholder="请选择工位">
          <el-option v-for="(item,idx) in stationList" :key="idx" :value="item.id" :label="item.name">
            <span style="color: #2761db">{{ item.name }}</span>
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input type="textarea" :autosize="{ minRows: 3, maxRows: 5}" v-model="form.remark" clearable placeholder="请输入备注" />
      </el-form-item>
    </el-form>
    <div class="xm-footer">
      <el-button type="primary" size="mini"  @click="saves">确 定</el-button>
      <el-button type="info" size="mini" @click="close">关 闭</el-button>
    </div>
  </section>
</template>

<script>
  import {getPrefer}  from '@/api/historymsg'
  import {addCpConfigs,editCpConfigs} from '@/api/xapi'
  import { add,update,getById } from '@/api/properties'
export default {
  props: {
    layerid: {
      default: 0
    },
    row: {
      default: {}
    }
  },
  data() {
    return {
      box_loading: false,
      btn_loading: false,
      stationList: [],
        form: {
          cpkLevel: undefined,
          testItem: undefined,
          code: undefined,
          nameValueK2101: undefined,
          lowValueK2110: undefined,
          highValueK2111: undefined,
          consoleType: undefined,
          remark: undefined,
          toolType: undefined,
          opName: undefined,
          station: undefined,
        },
      rules: {
          // importanceRank: [{ required: true, message: '必填', trigger: 'blur' }],
          // cp: [{ required: true, message: '必填', trigger: 'blur' }],
          // cpk: [{ required: true, message: '必填', trigger: 'blur' }],
      }
    }
  },
  mounted() {
    this.getAllPrefer();
    if (this.row.id) this.form = JSON.parse(JSON.stringify(this.row))
  },
  methods: {

    /* 添加、编辑 */
   async saves() {
        // this.$refs[formName].validate(async valid => {
        //     if (this.row.id) {
                var obj = JSON.parse(JSON.stringify(this.form))
                this.btn_loading = true;
                let res = '';
                if(this.row.id){
                  res = await update(obj)
                }else{
                  res = await add(obj)
                }
                this.btn_loading = false
                if (res.status && res.status != 200) {
                  // this.$message({ message: res.data.message, type: 'error' })
                  return false
                }
                Object.assign(this.$data.form, this.$options.data().form)
                this.$layer.close(this.layerid)
                this.$parent.getList()
                this.$message({ message: '操作成功', type: 'success' })
            // }
            // else {
            //     this.$refs[formName].validate()
            // }
        // })
    },
    async getAllPrefer() {
      await getPrefer().then(res => {
        // console.warn(res.data);
        this.stationList = res.data;
      })
    },
    // reset() {
    //   this.$refs.form.resetFields()
    //   // if (this.row.admin_role_id) this.form = JSON.parse(JSON.stringify(this.row))
    // },
    close() {
      this.$layer.close(this.layerid)
    }
  }
}
</script>
<style>
    .el-upload-list__item {
        transition: none !important;
    }
    .custom-tree-node {
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: space-between;
      font-size: 14px;
      padding-right: 8px;
    }
    .el-dialog .el-dialog__footer {
      z-index: 100;
    }
</style>
